﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic.Command;
using System.Text;
using Model;
//using System.Web.Script.Serialization;

namespace CO9APPFORM
{
    /// <summary>
    /// Summary description for GetAvailableWord
    /// </summary>
    public class GetAvailableWord : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            GetWordCommand cmd = new GetWordCommand();
            cmd.Execute();

            StringBuilder sb = new StringBuilder();
            sb.Append("[");

            foreach (APP_WORDING w in cmd.Result)
            {
                sb.Append("\"" + w.WORD + "\",");
            }

            sb.Remove(sb.Length - 1, 1);

            sb.Append("]");


            //var jsonSerialiser = new JavaScriptSerializer();
            //var json = jsonSerialiser.Serialize(list);

            string json = sb.ToString();

            context.Response.ContentType = "application/json";
            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class WORD
    {
        public string Text { get; set; }
    }
}